1 using System;
2 using
System.Collections;
3 using
System.Collections.Generic;
4 using
UnityEngine;
5
6 namespace
UnityStandardAssets.Utility
7 {
8     
public class ObjectResetter : MonoBehaviour
9     {
10         
private Vector3 originalPosition;
11         
private Quaternion originalRotation;
12         
private List<Transform> originalStructure;
13
14         
private Rigidbody Rigidbody;
15
16         
// Use this for initialization
17         
private void Start()
18         {
19             originalStructure =
new List<Transform>(GetComponentsInChildren<Transform>());
20             originalPosition = transform.position;
21             originalRotation = transform.rotation;
22
23             Rigidbody = GetComponent<Rigidbody>();
24         }
25
26
27         
public void DelayedReset(float delay)
28         {
29             StartCoroutine(ResetCoroutine(delay));
30         }
31
32
33         
public IEnumerator ResetCoroutine(float delay)
34         {
35             
yield return new WaitForSeconds(delay);
36
37             
// remove any gameobjects added (fire, skid trails, etc)
38             
foreach (var t in GetComponentsInChildren<Transform>())
39             {
40                 
if (!originalStructure.Contains(t))
41                 {
42                     t.parent =
null;
43                 }
44             }
45
46             transform.position = originalPosition;
47             transform.rotation = originalRotation;
48             
if (Rigidbody)
49             {
50                 Rigidbody.velocity = Vector3.zero;
51                 Rigidbody.angularVelocity = Vector3.zero;
52             }
53
54             SendMessage(
"Reset");
55         }
56     }
57 }


Gõ tìm kiếm nhanh...